package com.yanqu.road.server.cmd.activity.ppl;

import com.yanqu.road.pb.activity.PplProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ppl.PplModule;
import com.yanqu.road.server.manger.activity.ppl.PplMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ACTIVITY_PPL_CHOOSE_BEAUTY, desc = "泡泡龙选择美女")
public class ChooseBeautyCmd extends AbstractCommand {

    private int beautyId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        PplProto.ChooseBeautyReqMsg reqMsg = PplProto.ChooseBeautyReqMsg.parseFrom(packet.getBytes());
        beautyId = reqMsg.getBeautyId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!PplMgr.isActivityInChooseBeautyTime()) {
            ret = GameErrorCode.E_ACTIVITY_PPL_NO_IN_CHOOSE_BEAUTY_TIME;
            return;
        }

        PplModule pplModule = player.getModule(PplModule.class);
        ret = pplModule.chooseBeauty(beautyId);
    }

    @Override
    public void sendData(GamePlayer player) {
        PplProto.ChooseBeautyRespMsg.Builder builder = PplProto.ChooseBeautyRespMsg.newBuilder();
        builder.setRet(ret);
        player.sendPacket(ClientProtocol.U_ACTIVITY_PPL_CHOOSE_BEAUTY, builder);
    }
}
